package com.roocon.thread.net;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Date;

public class HttpServer {

  public static void main(String[] args) throws IOException {
    ServerSocket serverSocket = new ServerSocket(8899);
    while (!Thread.interrupted()) {
      Socket client = serverSocket.accept();
      //InputStream ins = client.getInputStream();
      //OutputStream out = client.getOutputStream();
      //
      //int len = 0;
      //byte[] b = new byte[1024];
      ////while ((len = ins.read(b)) != -1) {
      ////  System.out.println(new String(b,0,len));
      ////}
      //
      //// 读取内容
      //BufferedReader reader = new BufferedReader(new InputStreamReader(ins));
      //String line = reader.readLine();
      //System.out.println(line);
      //
      //// 给用户响应
      //PrintWriter pw = new PrintWriter(out);
      //InputStream i = new FileInputStream("D:\\opt\\index.html");
      //BufferedReader bf = new BufferedReader(new InputStreamReader(i));
      //String c ;
      //pw.println("HTTP/1.1 200 OK");
      ////pw.println("Content-Type:text/html;charset=utf-8");
      ////pw.println("Content-Length:" + i.available());
      ////pw.println("Date:" + new Date());
      ////pw.println("Server: Hello");
      //pw.println(""); //这个换行很重要
      //pw.flush();
      //while ((c = bf.readLine()) != null) {
      //  pw.println(c);
      //}
      //pw.flush();

      new Thread(new ServerThread(client)).start();
    }

    serverSocket.close();
  }
}
